package com.szh.zx.gaoDingJavaBook.chapter8.three;

import java.util.TreeSet;

/**
* 实现定制排序
* */
class M{
	int age;

	public M(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "M{" +
				"age=" + age +
				'}';
	}
}
public class TreeSetTest4 {
	public static void main(String[] args) {
//		此处Lambda 表达式的目标类型是compare
		TreeSet  treeSet = new TreeSet(((o1, o2) -> {
			M m1 = (M) o1;
			M m2 = (M) o2;
//			根据M 对象的age属性来决定大小，age越大，M对象越小
			return m1.age > m2.age ? -1:m1.age<m2.age ? 1:0;
		}));
		treeSet.add(new M(5));
		treeSet.add(new M(-3));
		treeSet.add(new M(9));
		System.out.println(treeSet);
























	}
}
